package com.inossem.warehousestorage_inossem.request.changeStorage.chuangyou;

import android.content.Context;

import com.google.gson.Gson;
import com.inossem.utils.log.LogUtils;
import com.inossem.warehousestorage_inossem.bean.changeStorage.chuangyou.CYChangeStorageMaterialListBean;
import com.inossem.warehousestorage_inossem.bean.changeStorage.chuangyou.CYChangeStoragePurchaseOrderBean;
import com.inossem.warehousestorage_inossem.constant.RequestConstant;
import com.inossem.warehousestorage_inossem.listener.GsonBeanListener;
import com.inossem.warehousestorage_inossem.listener.StringRequestListener;
import com.inossem.warehousestorage_inossem.manage.RequestManage;
import com.inossem.warehousestorage_inossem.model.StringResponse;
import com.inossem.warehousestorage_inossem.request.Request;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * TODO
 *
 * @author 王斯宇
 * @time on 2018/3/29 19:39
 * @email siyu.wang@inossem.com
 */
public class CYChangeStorageMaterialListRequest extends Request {
    private static final String PURCHASE_ORDER_CODE_LIST = "purchase_order_code_list";
    private static String code;

    public static String request(Context context, List<String> purchaseOrderCode , GsonBeanListener gsonBeanListener) {
        String tag;
        code = "";
        Map<String, String> params = new HashMap<>();
        for (int i = 0; i < purchaseOrderCode.size(); i++) {
            if (i != purchaseOrderCode.size()-1) {
                code += purchaseOrderCode.get(i) +",";
            }else {
                code += purchaseOrderCode.get(i);
            }
        }
        LogUtils.i("code === " + code);
        params.put(PURCHASE_ORDER_CODE_LIST , code);
        String methodUrl = RequestConstant.CY_URL_CHANGE_STORAGE_GET_MATERIAL_LIST;
        String url = RequestManage.getUrl(context, methodUrl + RequestManage.mapToParams(params));
        tag = RequestManage.getHttpsGetWithLoading(context, url, new StringRequestListener() {
            @Override
            public void onSuccess(StringResponse stringRequestResponse) {
                Gson gson = new Gson();
                CYChangeStorageMaterialListBean bean = gson.fromJson(stringRequestResponse.getResponseInfo(), CYChangeStorageMaterialListBean.class);
                excuteJsonBeanNew(context, bean,gsonBeanListener);
            }
        });
        return tag;
    }
}
